package com.application.service;

import com.application.ContractAppService;
import com.application.request.ContractRequest;
import com.application.request.OperationLogRequest;
import com.application.response.OperationLogResponse;
import com.inboyu.admin.domain.ContractDomainService;
import com.inboyu.admin.domain.ContractEntity;
import com.inboyu.admin.domain.OperationLogEntity;
import com.inboyu.admin.domain.ResourceEntity;

import java.util.List;

public class ContractAppServiceImpl implements ContractAppService {

    private final ContractDomainService contractDomainService;

    public ContractAppServiceImpl(final ContractDomainService contractDomainService) {
        this.contractDomainService = contractDomainService;
    }

    @Override
    public void saveContract(ContractRequest contract) {
        ContractEntity contractEntity = contract.toContractEntity();
        int count = contractDomainService.saveContract(contractEntity);
    }

    @Override
    public void saveResource(ResourceEntity resource) {
        int count = contractDomainService.saveResource(resource);
    }

    @Override
    public List<OperationLogResponse> findOperationLogByCondition(OperationLogRequest request) {
        List<OperationLogEntity> operationLogs = contractDomainService.findOperationLogByCondition(request.storeId(), request.operator(),
                request.operationTimeStart(), request.operationTimeEnd());
        return OperationLogResponse.convertList(operationLogs);
    }
}
